package indi.kider.server.applandlord.api;

import indi.kider.common.model.apabus.Bus;
import indi.kider.common.model.apabus.Rent;
import indi.kider.server.applandlord.service.related.ApaBusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pers.vankid.common.model.base.CommonResponse;
import pers.vankid.common.utils.page.PageRequest;
import pers.vankid.common.utils.page.PageResponse;

import java.util.List;

@RestController
@RequestMapping(value = "bus", produces = "application/json;charset=UTF-8")
public class BusController {
    @Autowired
    private ApaBusService apaBusService;

    /**
     * @api {POST} bus/rentHouse
     * @apiGroup app-landlord
     * @apiDescription 用户租房
     * @apiParamExample 请求样例：
     * http://localhost:9002/app-landlord/bus/rentHouse
     * {"rentDate":"2018-05-06","expireDate":"2019-05-06","housesId":"82","initWaterReading":"10","initPowerReading":"10","tenantName":"wbb","tenantTel":"13333333333","cardId":"44","remark":"44"}
     * @apiSuccessExample {json} 返回样例:
     * {
     * "status": "201",
     * "msg": "保存成功！",
     * "data": 1
     * }
     */
    @PostMapping("/rentHouse")
    public CommonResponse<Rent> rentHouse(@RequestBody Rent rent) {
        return apaBusService.rentHouse(rent);
    }

    /**
     * @api {PUT} bus/rentHouse
     * @apiGroup app-landlord
     * @apiDescription 用户退房
     * @apiParamExample 请求样例：
     * http://localhost:9002/app-landlord/bus/rentHouse
     * {"id":1,"housesId":12,"tenantId":13}
     * @apiSuccessExample {json} 返回样例:
     * {
     * "status": "202",
     * "msg": "保存成功！",
     * "data": 1
     * }
     */
    @PutMapping("/rentHouse")
    public CommonResponse checkOutHouse(@RequestBody Rent rent) {
        return apaBusService.checkOutHouse(rent);
    }

    /**
     * @api {POST} bus/service/list
     * @apiGroup app-landlord
     * @apiDescription 根据字段查询获取服务列表（分页）
     * @apiParamExample 请求样例：
     * http://localhost:9002/app-landlord/bus/service/list
     * {"num":"0","size":"8","query":{"community":null,"houses":null,"des":null,tenantName":null,"tenantTel":null,"busType":1}}
     * @apiSuccessExample {json} 返回样例:
     * {"status":"200","msg":"查询成功！","data":{"rows":[{"busType":null,"community":null,"des":null,"employeeId":null,"evaluation":null,"evsu":null,"evsuTime":null,"houses":null,"housesId":null,"id":null,"insTime":null,"result":null,"resutlTime":null,"state":null,"tenantId":null,"tenantName":null,"tenantTel":null,"waiter":null,"waiterTime":null}],"total":1,"size":0}}
     */
    @PostMapping("service/list")
    public CommonResponse<PageResponse> getPageServiceList(@RequestBody PageRequest<Bus> request) {
        return apaBusService.getPageServiceList(request);
    }
}
